import { AnyAction } from "redux";
import { produce } from 'immer';
import { User } from "../../../api/interface";
import { SET_USERINFO } from "./action";
import AvatarImg from '../../../assets/avatar.png';
export interface UserState {
    userinfo:User.Userinfo,
}

const userState:UserState = {
    userinfo:{
        username:'',
        avatar:AvatarImg
    }
};

const reducer = (state: UserState = userState, action: AnyAction) =>
    produce(state, drafState=>{
        switch (action.type) {
            case SET_USERINFO:
                drafState.userinfo = action.userinfo;
                break;
            default:
                return drafState;
        }
    });

export default reducer;
